package com.hotel.controller;

import com.hotel.pojo.Admin;
import com.hotel.service.AdminServiceImpl;
import jdk.nashorn.internal.objects.NativeJSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/admin")

public class AdminController {

    @Autowired
    AdminServiceImpl adminService;

    @RequestMapping("/login")
    public String login(String username, int password){
        //判断用户是否存在
       Admin admin=adminService.findAdmin(username,password);
       if(admin!=null){
           if(admin.getPassword()==password){
               if ("admin".equals(username)){
                   return "index";
               }else if ("recep".equals(username)){
                   return "indexRecep";
               }else {
                   return "indexCleaner";
               }
           }
           else {
                return "loginAgain";
           }
       }
        return "loginAgain";
    }

    @RequestMapping("/updatePwd")
    public String update(Admin admin){
        adminService.updatePwd(admin)   ;
        System.out.println(admin);
        return "loginAgainTwo";
    }
}
